package com.jianzong.lingxuan.api.service.impl;

import com.anji.captcha.model.vo.CaptchaVO;
import com.jianzong.lingxuan.api.service.ApiService;
import com.jianzong.lingxuan.api.service.SectUserService;
import com.jianzong.lingxuan.base.Result;
import com.jianzong.lingxuan.enums.ApiEnum;
import com.jianzong.lingxuan.enums.SysInfo;
import com.jianzong.lingxuan.error.SysError;
import org.springframework.stereotype.Service;

import java.util.Map;

import static com.jianzong.lingxuan.enums.ApiEnum.LOGIN;

/**
 * @auth Leiwenlong
 * @since 2021/7/19
 *   统一处理类
 */
@Service
public class ApiServiceImpl implements ApiService {

    public final SectUserService sectUserService;

    public ApiServiceImpl(SectUserService sectUserService){
        this.sectUserService = sectUserService;
    }

    @Override
    public Result<?> action(Map<String, String[]> map, String token, CaptchaVO captchaVO) {

        if(map.get("action").length< 0){
            return Result.error("");
        }

        String[] actions = map.get("action");
        String action = actions[0];

        switch (ApiEnum.getByName(action)){
            case LOGIN:
                System.out.println("This is Login Action...");
                return sectUserService.login(map,captchaVO);
            case REGISTER:
                System.out.println("This is REGISTER Action...");
                return sectUserService.register(map);
            case FRIENDLIST:
                System.out.println("This is FRIENDLIST Action...");
                return sectUserService.friendList(map,token);
            case GONGFALIST:
                System.out.println("This is GONGFALIST Action...");
                return sectUserService.GongfaList(map,token);
            case GETUSERINFO:
                System.out.println("This is GETUSERINFO Action...");
                return sectUserService.getUserInfo(map,token);
            case LOGINBYID:
                System.out.println("This is LOGINBYID Action...");
                return sectUserService.loginById(map);
            case QUERYTASKLIST:
                System.out.println("This is QUERYTASKLIST Action...");
                return sectUserService.queryTaskList(map,token);
            case QUERYUSERPETSLIST:
                System.out.println("This is QUERYUSERPETSLIST Action...");
                return sectUserService.queryUserPetsList(map,token);
            case QUERYUSERPETSSKILLLIST:
                System.out.println("This is QUERYUSERPETSSKILLLIST Action...");
                return sectUserService.queryUserPetsSkillList(map,token);
            case GETEMAILINFO:
                System.out.println("This is GETEMAILINFO Action...");
                return sectUserService.getEmailInfo(map,token);
            case QUERYUSERMOUNTLIST:
                System.out.println("This is QUERYUSERMOUNTLIST Action...");
                return sectUserService.queryUserMountList(map,token);
            case QUERYUSERMOUNTSKILLLIST:
                System.out.println("This is QUERYUSERMOUNTSKILLLIST Action...");
                return sectUserService.queryUserMountSKillList(map,token);
            case SIMULATIONPK:
                System.out.println("This is SIMULATIONPK Action...");
                return sectUserService.simulationPK(map, token);
            case ADDFRIEND:
                System.out.println("This is ADDFRIEND Action...");
                return sectUserService.addFriend(map, token);
            case QUERYFRIENDAPPLICANTLIST:
                System.out.println("This is QUERYFRIENDAPPLICANTLIST Action...");
                return sectUserService.queryFriendApplicantList(map, token);
            default:
                return Result.error(SysInfo.PARAM_NOTACTION);
        }

    }

}
